<template>
    <div id="app-other">
        <div class="one-block-1">
            <span> 1.浏览器引擎像素流 </span>
        </div>
        <div class="one-block-2">
            <a-space>
                <a-button type="primary" @click="openPixel">开启</a-button>
                <a-button type="info" @click="closePixel">关闭</a-button>
                <a-button type="info" @click="sendRandomWebsocketStr">发送随机消息</a-button>
            </a-space>
        </div>

        <div class="one-block-1">
            <span> 2.桌面端虚拟引擎</span>
        </div>
        <div class="one-block-2">
            <a-space>
                <a-button type="primary" @click="handleStartDesktop">启动</a-button>
                <a-button type="" @click="handleEndDesktop">关闭</a-button>
            </a-space>
        </div>

        <div class="one-block-1">
            <span> 3.测试本地服务</span>
        </div>
        <div class="one-block-2">
            <a-space>
                <a-button type="primary" @click="handleOpenLocalServer">打开</a-button>
                <a-button type="danger" @click="handleCloseLocalServer">关闭</a-button>
            </a-space>
        </div>

        <div class="one-block-1">
            <span> 4.操作sqlite</span>
        </div>
        <div class="one-block-2">
            <a-space>
                <a-button type="primary" @click="handleAdd">添加</a-button>
                <a-button type="primary" @click="handleUpdate">修改</a-button>
                <a-button type="primary" @click="handleDelete">删除</a-button>
                <a-button type="primary" @click="handleAll">所有</a-button>
                <a-button type="primary" @click="handleSingle">单条</a-button>
            </a-space>
        </div>
    </div>
</template>
<script>
import { ipcApiRoute } from "@/api/main";
import { mapMutations, mapState } from "vuex";
import { v4 as uuidv4 } from "uuid";

export default {
    data() {
        return {};
    },
    computed: {
        ...mapState("test", ["counter"]),
    },
    methods: {
        ...mapMutations("test", ["set_counter"]),
        openPixel() {
            const self = this;
            this.$ipcInvoke(ipcApiRoute.openPixelStream).then((r) => {
                self.$message.info(r);
            });
        },

        closePixel() {
            const self = this;
            this.$ipcInvoke(ipcApiRoute.closePixelStream).then((r) => {
                self.$message.info(r);
            });
        },
        handleClickCounter() {
            this.set_counter();
        },

        // 打开本地服务
        handleOpenLocalServer() {
            const self = this;
            this.$ipcInvoke(ipcApiRoute.openLocalServe).then((r) => {
                self.$message.info(r);
            });
        },
        // 关闭本地服务
        handleCloseLocalServer() {
            const self = this;
            this.$ipcInvoke(ipcApiRoute.closeLocalServe).then((r) => {
                self.$message.info(r);
            });
        },

        handleAdd() {
            const self = this;
            let data = {
                id: uuidv4.v4(),
                state: 3,
                fileName: uuidv4.v4() + ".png",
                progress: "20",
                isError: 0,
                remake: "上传中",
                filePath: "E:We3D_PROJmasterCCCCBIM-VDCxVDCVDCScreenShot",
                uploaded: "",
                fileFullName: uuidv4.v4(),
                isDeleted: 0,
                fileSize: 100,
                uploadId: uuidv4.v4(),
                uploadPath: "VDC/llr/1663318120-screenshot_1663318119087.png",
                partSize: 12,
                lastPartSize: 13,
                partCount: 100,
                folderId: uuidv4.v4(),
                uploadDir: "",
                previewPath: "",
                objectJson: "{name:'hello'}",
                workid: "1111",
                storagePath: "111",
            };
            this.$ipcInvoke(ipcApiRoute.addTaskData, data).then((r) => {
                console.log(r);
            });
        },
        handleUpdate() {
            this.$ipcInvoke(ipcApiRoute.updateTaskDataById, {
                id: "eec5205b-54af-428e-b0b1-5f36b74b912b",
                progress: +(Date.now() + "").substr(8, 2),
            }).then((r) => {
                console.log(r);
            });
        },

        async handleAll() {
            const data = await this.$ipcInvoke(ipcApiRoute.getAllTaskData);
            console.log(data);
        },

        handleSingle() {},
        handleDelete() {},

        handleStartDesktop() {
            const self = this;
            self.$ipcInvoke(ipcApiRoute.startDesktopExe).then((r) => {
                self.$message.info(r);
            });
        },
        handleEndDesktop() {
            const self = this;
            self.$ipcInvoke(ipcApiRoute.endDesktopExe).then((r) => {
                self.$message.info(r);
            });
        },

        sendRandomWebsocketStr() {
            const self = this;
            self.$ipcInvoke(
                ipcApiRoute.sendMsgThroughWebsocket,
                Date.now() + "hello world"
            ).then((r) => {
                self.$message.info(r);
            });
        },
    },
};
</script>
<style lang="less" scoped>
#app-other {
    padding: 0px 10px;
    text-align: left;
    width: 100%;
    .one-block-1 {
        font-size: 16px;
        padding-top: 10px;
    }
    .one-block-2 {
        padding-top: 10px;
    }
}
</style>
